#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
#define calc(xls, fold) ((fold) + (xls > x) + (a - xls < na - x))
 
typedef class dp_t {
public:
    int v0, p1, p2, a;
    dp_t() {}
    dp_t(int v0, int p1, int p2, int a) : v0(v0), p1(p1), p2(p2), a(a) {}
 
    int eval(int x, int na) {
        int rt = calc(0, v0);
        if (p1 <= a)
            rt = min(rt, calc(p1, v0 - 1));
        if (p2 <= a)
            rt = min(rt, calc(p2, v0 - 2));
        return rt;
    }
    dp_t trans(int na) {
        dp_t rt(0, 0, 0, na);
        rt.v0 = eval(0, na);
        int l = 0, r = na, mid;
        while (l <= r) {
            mid = (l + r) >> 1;
            if (eval(mid, na) == rt.v0) {
                l = mid + 1;
            }
            else {
                r = mid - 1;
            }
        }
        rt.p1 = l;
        r = na;
        while (l <= r) {
            mid = (l + r) >> 1;
            if (eval(mid, na) == rt.v0 - 1) {
                l = mid + 1;
            }
            else {
                r = mid - 1;
            }
        }
        rt.p2 = l;
        return rt;
    }
} dp_t;
 
int n;
int a[N];
 
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> *(a + i);
    }
    dp_t f(0, 1, 1, 0);
    for (int i = 1; i <= n; i++)
        f = f.trans(a[i]);
    f = f.trans(0);
    cout << f.v0;
    return 0;
}